﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ahi.Config;
using DevExpress.XtraLayout;
using System.IO;

namespace Ahi.Base
{
    public class BaseForm : DevExpress.XtraEditors.XtraForm
    {
        public BaseForm()
        {
            Id = new IdFormParameter();
        }

        public bool IsDialog { get; set; }

        public IdFormParameter Id { get; set; }

        public bool IsLoading { get; private set; }

        protected override void OnLoad(EventArgs e)
        {
            IsLoading = true;
            base.OnLoad(e);
            if (DesignMode) return;

            if (!IsDialog)
            {
                if (!this.IsMdiContainer)
                    this.MdiParent = Program.MainForm;
                this.FormClosed += (object sender, FormClosedEventArgs arg) => Program.MainForm.ChildFormClosed(this);
                Program.MainForm.ChildFormOpened(this);
            }
            else
            {
                StartPosition = FormStartPosition.CenterScreen;
                //ShowInTaskbar = false; // runtime da formun kapanmasına sebep oluyor
            }

            LoadLayouts();

            Hazirla();
            Yukle();
            IsLoading = false;
        }

        private void LoadLayouts()
        {
            //if(File.Exists(AppConfig.Current.LayoutDizini + 
            //if (!string.IsNullOrEmpty(AppConfig.Current.FormLayouts[this.Text]))
            //{
            //    var controls =  this.Controls.Find("layoutControl1", true);
            //    if(controls!=null && controls.Length>0){
            //    LayoutControl layout =controls[0] as LayoutControl;
               
            //}}
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            SaveLayouts();
            base.OnClosing(e);
        }

        private void SaveLayouts()
        {

        }

        public virtual void Hazirla() { }

        public virtual void Yukle() { }

        public virtual void Kaydet() { }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // BaseForm
            // 
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "BaseForm";
            this.ResumeLayout(false);

        }
    }
}
